#include<bits/stdc++.h>
#define int long long
#define double long double
#define PB push_back
#define maxn 100007
#define bit(x,i) ((x>>i)&1)
#define S second
#define F first
#define MP make_pair
#define epsilon 0.000001
using namespace std;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int inf = 1e18;
const int mod = 1e9+7;
int add(int x, int y){
int s=x+y;
if (s>mod) s-=mod;
return s;
}
int n,m,a,b;
void readData(){
cin>>n>>m>>a>>b;
}
void solve(){
if (n*a!=b*m){
cout<<"NO"<<"\n";
return;
}
cout<<"YES"<<"\n";
int d=0;
for (int i=1;i<m;i++)
if ((i*n)%m==0){
d=i;
break;
}
int ans[n+1][m+1];
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
ans[i][j]=0;
int dak=0;
for (int i=0;i<n;i++){
dak+=d;
for (int j=0;j<a;j++)
ans[i][(j+dak)%m]=1;
}
for (int i=0;i<n;i++){
for (int j=0;j<m;j++)
cout<<ans[i][j];
cout<<"\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen(".inp","r",stdin);
//freopen(".out","w",stdout);
int t;
cin>>t;
while (t--){
readData();
solve();
}
return 0;
}
/*
_oo0oo_
o8888888o
88" . "88
(| -_- |)
0\ = /0
___/`---'\___
.' \\| |// '.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' |_/ |
\ .-\__ '-' ___/-. /
___'. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' >' "".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `_. \_ __\ /__ _/ .-` / /
=====`-.____`.___ \_____/___.-`___.-'=====
`=---='
*/
1000B - Light It Up | 218B - Airport |
1463B - Find The Array | 1538C - Number of Pairs |
621B - Wet Shark and Bishops | 476B - Dreamoon and WiFi |
152C - Pocket Book | 1681D - Required Length |
1725D - Deducing Sortability | 1501A - Alexey and Train |
721B - Passwords | 1263D - Secret Passwords |
1371B - Magical Calendar | 1726E - Almost Perfect |
1360C - Similar Pairs | 900A - Find Extra One |
1093D - Beautiful Graph | 748A - Santa Claus and a Place in a Class |
1511B - GCD Length | 676B - Pyramid of Glasses |
597A - Divisibility | 1632A - ABC |
1619D - New Year's Problem | 242B - Big Segment |
938A - Word Correction | 159C - String Manipulation 10 |
258A - Little Elephant and Bits | 1536C - Diluc and Kaeya |
1428C - ABBB | 1557A - Ezzat and Two Subsequences |